﻿@using KPIS.GERP.Models.SYS.Resources
@model KPIS.GERP.Models.ICM.Bid

@{
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
    ViewBag.Title = "แก้ไขข้อมูลประกาศ [BI]";
    ViewBag.Descr = "ข้อมูลประกาศซื้อจ้าง";
}

@using (Html.BeginForm("Edit", "Bid", FormMethod.Post, new { @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()

    <div class="block-button-menu-above"> 
        @Html.ButtonCancel(new { Id = Model.BidId, showApproveButton = ViewBag.ShowApproveButton })
        @Html.ButtonSubmit()
    </div>
    
    <div class="alert-error">
    @Html.ValidationSummary()
    </div>
    @Html.Partial("_EditorForm")

}

@section scripts
{
    <script>
        function ReceiveTypeChange(value) {
            if (value == 'F'){
                $("#divDocumentAmount").hide();
            }
            else if (value == 'S') {
                $("#divDocumentAmount").show();
            }
        }

        $("form").submit(function (e) {
            e.preventDefault();
            var currentForm = this;
            bootbox.confirm(function (result) {
                if (result) {
                    currentForm.submit();
                }
            });
        });

        $(function () {
            ReceiveTypeChange('@(Model.ReceiveType)');

            $(".time-picker").timepicker({
                minuteStep: 1,
                showSeconds: false,
                showMeridian: false,
                defaultTime: false
            });

            $("#txtReceiveDate").val('@(Model.ReceiveDateStart.HasValue ? Model.ReceiveDateStart.Value.ToShortDateString() + " - " : "")@(Model.ReceiveDateEnd.HasValue ? Model.ReceiveDateEnd.Value.ToShortDateString() : "")');
            $("#txtOfferDate").val('@(Model.OfferDateStart.HasValue ? Model.OfferDateStart.Value.ToShortDateString() + " - " : "")@(Model.OfferDateEnd.HasValue ? Model.OfferDateEnd.Value.ToShortDateString() : "")');

            $("#txtReceiveDate").daterangepicker(
                {},
                function(start, end) {
                    var dateRange = $('#txtReceiveDate').val();

                    if (dateRange.length > 0) {
                        var dateSplit = dateRange.split(" - ");
                        $("#txtReceiveDateStart").val(dateSplit[0]);
                        $("#txtReceiveDateEnd").val(dateSplit[1]);
                    }
                    else {
                        $("#txtReceiveDateStart").val("");
                        $("#txtReceiveDateEnd").val("");
                    }
                }
            );
            $("#txtOfferDate").daterangepicker(
                {},
                function (start, end) {
                    var dateRange = $('#txtOfferDate').val();

                    if (dateRange.length > 0) {
                        var dateSplit = dateRange.split(" - ");
                        $("#txtOfferDateStart").val(dateSplit[0]);
                        $("#txtOfferDateEnd").val(dateSplit[1]);
                    }
                    else {
                        $("#txtOfferDateStart").val("");
                        $("#txtOfferDateEnd").val("");
                    }
                }
            );
        });
    </script>
}